 function getParam ( sname )
 {
  var tag_iframe_URL = window.location.href;
  var sval = "";
  if (tag_iframe_URL && tag_iframe_URL.indexOf("?") > 0) {
    var params = tag_iframe_URL.substr(tag_iframe_URL.indexOf("?")+1);
    if (params) {
      params = params.split("&");
        // split param and value into individual pieces
        for (var i=0; i<params.length; i++)
         {
           temp = params[i].split("=");
           if ( [temp[0]] == sname ) { sval = temp[1]; }
         }
    }
  }
  return sval;
 }
 function decod(s) {
  if(typeof decodeURIComponent == 'function') return decodeURIComponent(s);
  else return unescape(s);
 }
 if (window.location != window.parent.location) {
  // we are running in an iframe
  var iframeloc = window.location.href;
  if (iframeloc) {
     if (iframeloc.indexOf('.doubleclick.net/') > 0 && iframeloc.indexOf(';dc_ref=') > 0) {
        // Running in DFP iframe
        var page_url = iframeloc.substring(iframeloc.indexOf(';dc_ref=') + 8);
        if (page_url && page_url.indexOf(';') > 0) {
           page_url = page_url.substring(0,page_url.indexOf(';'));
        }
        if (page_url) {
           admeld_custom1 = 2; // DFP iframe dc_ref parameter
           admeld_custom2 = decod(page_url);
        }
     } else {
        // Running in other iframe
	if (iframeloc.indexOf('.admeld.com/') > 0) {
           // Admeld iframe
           var iframe_url_param = getParam('url');
           var iframe_cf2_param = getParam('cf2');
           // prefer cf2 if defined
           if (iframe_cf2_param) {
              admeld_custom1 = 3; // Admeld cf2 parameter forwarding
              admeld_custom2 = decod(iframe_cf2_param);
           } else {
              if (iframe_url_param) {
                 admeld_custom1 = 4; // Admeld url parameter forwarding
                 admeld_custom2 = decod(iframe_url_param);
              } else {
                 // fallback to hardcoded
              }
           }
        } else {
           // Running in another iframe: use the iframe URL
           admeld_custom1 = 5; // iframe location
           admeld_custom2 = decod(window.location.href);
        }
     }
  } else {
     admeld_custom1 = 6; // No location available
  }
 } else {
   // Running in main page: take the location
   admeld_custom1 = 7; // page location
   admeld_custom2 = decod(window.location.href);
 }